<template>
	<div class="content">
		<div class="clear">
			<Form inline class="fl">
				<Input type="text" placeholder="请输入用户名" class="w200 m-r10" v-model.trim="userName" />
				<Button type="primary" v-on:click="query">查询</Button>
			</Form>
		</div>
		<!--<json-view :data="content"></json-view>-->
		<Table stripe :columns="columns" ref="table" :data='list'></Table>
		<Page :total="info" show-elevator :page-size="pageSize" show-total @on-change="cuctGetQuery" :current.sync="page"></Page>
	</div>
</template>
<script>
	export default {
		data() {
			return {
				list: [], // 分享收益列表数据
				info: null, // 总条数
				page: 1, // 页数
				pageSize: 20, // 每页多少条
				current: 1,
				userName: '',
				content: '{"rating":{"max":10,"average":9.6,"stars":"50","min":0}}',
				columns: [{
						title: '用户名',
						align: 'center',
						key: 'userName',
						render: (h, params) => {
							return h('div', params.row.userName == null ? '#' : params.row.userName)
						}
					},
					//  {
					// 	title: 'ip',
					// 	align: 'center',
					// 	key: 'reqIp',
					// 	render: (h, params) => {
					// 		return h('div', params.row.reqIp == null ? '#' : params.row.reqIp)
					// 	}
					// },
					{
						title: '方法描述',
						align: 'center',
						key: 'methodDesc',
						render: (h, params) => {
							return h('div', params.row.methodDesc == null ? '#' : params.row.methodDesc)
						}
					},
					{
						title: 'url',
						align: 'center',
						key: 'url',
						render: (h, params) => {
							return h('div', params.row.url == null ? '#' : params.row.url)
						}
					},
					{
						title: '请求参数',
						align: 'center',
						key: 'params',
						render: (h, params) => {
							return h('div', [
								h('pre', {
									style: {
//										marginRight: '5px'
									},
								}, params.row.params == null ? '#' : params.row.params)
							])
						}
					},
					{
						title: '业务类型',
						align: 'center',
						key: 'bizType',
						render: (h, params) => {
							return h('div', params.row.bizType == null ? '#' : params.row.bizType)
						}
					},
					{
						title: '创建时间',
						align: 'center',
						key: 'createTime',
						render: (h, params) => {
							return h('div', params.row.createTime == null ? '#' : this.stringToTime(params.row.createTime))
						}
					}
				]
			}
		},
		created() {

		},
		mounted() {
			this.$Message.config({
				top: 250
			})
			this.getQuery()
		},
		methods: {
			getQuery() {
				let token = localStorage.getItem('mytoken')
				this.axios.get('/admin/log/logs?current=' + this.page + '&size=' + this.pageSize, {
					headers: {
						Authorization: 'bearer ' + token
					}
				}).then(res => {
					if(res.data.code == 200) {
						this.list = res.data.data.records;
						this.info = res.data.data.total;
					} else if(res.data.code == 500) {
						this.$Message.info(res.data.msg)
					}
				})
			},
			cuctGetQuery(page) {
				let token = localStorage.getItem('mytoken')
				this.axios.get('/admin/log/logs', {
					params: {
						current: page, // 当前页【可选，默认1】
						size: this.pageSize, // 每页记录数【可选，默认20】
						userName: this.userName
					}
				}, {
					headers: {
						Authorization: 'bearer ' + token
					}
				}).then(res => {
					if(res.data.code == 200) {
						this.list = res.data.data.records;
						this.info = res.data.data.total;
					}
				})
			},
			query() {
				let token = localStorage.getItem('mytoken')
				this.axios.get('/admin/log/logs', {
					params: {
						current: this.page, // 当前页【可选，默认1】
						size: this.pageSize, // 每页记录数【可选，默认20】
						userName: this.userName
					}
				}, {
					headers: {
						Authorization: 'bearer ' + token
					}
				}).then(res => {
					if(res.data.code == 200) {
						this.list = res.data.data.records;
						this.info = res.data.data.total;
					} else if(res.data.code == 500) {
						this.$Message.info(res.data.msg)
					}
				})
			}
		}
	}
</script>

<style scoped>
	.clear {
		margin-bottom: 15px;
	}
	
	/deep/ pre {
		white-space: normal;
	}
</style>